﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Edu.Web.Data.DAO;
using Edu.Web.Data.DV;
using Edu.Web.Data.Entity;
using ESoft.Core.Data.DAO;
using ESoft.Core.Data.Service.Impl;
using ESoft.Core.Interceptor;

namespace Edu.Web.Data.Service.Impl
{
    public class AttendanceService : BaseService<AttendanceEntity, long>, IAttendanceService
    {
        private readonly IAttendanceDAO _attendanceDao;
        private readonly IAttendanceGroupDAO _attendanceGroupDao;

        public AttendanceService(IAttendanceDAO attendanceService, IAttendanceGroupDAO attendanceGroupService) : base(attendanceService)
        {
            _attendanceDao = attendanceService;
            _attendanceGroupDao = attendanceGroupService;
        }

        [TransactionalAttribute]
        public void AddList(List<AttendanceEntity> attendanceList, long userId, long clazzId)
        {
            AttendanceGroupEntity group = new AttendanceGroupEntity();
            group.GroupName = DateTime.Now.ToString("yyyy-MM-dd 考勤记录");
            group.CreateTime = DateTime.Now;
            group.ClazzId = clazzId;
            group.CreateUserId = userId;
            var groupPO = _attendanceGroupDao.Add(group);
            foreach (var attendance in attendanceList)
            {
                attendance.AttendanceGroupId = groupPO.Id;
                base._baseDao.Add(attendance);
            }
        }

        public AttendanceGroupDV GetAttendanceGroupById(long id)
        {
            return _attendanceDao.GetAttendanceGroupById(id);
        }

        public List<AttendanceDV> GetAttendanceListByGroupId(long groupId)
        {
            return _attendanceDao.GetAttendanceListByGroupId(groupId).ToList();
        }

        public List<AttendanceGroupDV> GetGroupListByCreateUid(long uid)
        {
            return _attendanceDao.GetAttendanceListByCreateUid(uid).ToList();
        }
    }
}